package za.co.chaotik.tron.screens;

import za.co.chaotik.tron.AbstractMap;
import za.co.chaotik.tron.CycleGame;
import za.co.chaotik.tron.Player;
import za.co.chaotik.tron.ScreenTransitionGame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class GameOverScreen extends CycleGameScreen {
	private static final String LOG = CycleGame.class.getSimpleName();
	private AbstractMap map;
	private SpriteBatch sb;
	private BitmapFont font;
	
	public GameOverScreen(ScreenTransitionGame game, AbstractMap map) {
		super(game);
		
		this.map = map;
		
		sb = new SpriteBatch();
		font = new BitmapFont(); // Use the default libGDX font (Arial 15pt)
	}

	@Override
	public void dispose() {
	}

	@Override
	public void render(float delta) {
		sb.begin();
		
		if (map.getPlayers().size() != 1) {
			String msg = "Invalid end-game state!";
			TextBounds bounds = font.getBounds(msg);
			font.setColor(Color.LIGHT_GRAY);
			font.draw(sb, msg,
					Gdx.graphics.getWidth() / 2.0f - bounds.width / 2.0f,
					Gdx.graphics.getHeight() / 2.0f - bounds.height / 2.0f);
		} else {
			Player p = map.getPlayers().get(0);
			String msg = p.getName() + " wins!";
			TextBounds bounds = font.getBounds(msg);
			font.setColor(p.getColor());
			font.draw(sb, msg,
					Gdx.graphics.getWidth() / 2.0f - bounds.width / 2.0f,
					Gdx.graphics.getHeight() / 2.0f - bounds.height / 2.0f);
		}
		
		sb.end();
	}

	@Override
	public void resize(int width, int height) {
	}

	@Override
	public void pause() {
	}

	@Override
	public void resume() {
	}

	@Override
	public void show() {
		Gdx.app.log(LOG, "Showing screen...");
	}

	@Override
	public void hide() {
		Gdx.app.log(LOG, "Hiding screen...");
	}
}
